﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using tmAsk.Common;

namespace tmAsk.Manager
{
    public partial class Login : System.Web.UI.Page
    {

        function make_htm = new function();//继承类
        tmAsk.Data.MakehtmlSQL SQL = new tmAsk.Data.MakehtmlSQL();

        protected void Page_Load(object sender, EventArgs e)
        {

        }
        protected void Submit_OnClick(object sender, EventArgs e)
        {
            string UserName = this.UserName.Text;
            string UserPassword = this.Password.Text;
            string podecode = this.ValidateCode.Text;
            if (Session["CheckCode"].ToString().Trim().ToLower() == podecode.Trim().ToLower())
            {
                if (function.CheckNull(UserName, UserPassword))
                {
                    DataSet ds = SQL.GetList("B_admin", "a_username='" + UserName.Trim().Replace("'", "") + "'", "a_userpassword");
                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        string m = make_htm.Md5(UserPassword);
                        if (ds.Tables[0].Rows[0]["a_userpassword"].ToString() == m)
                        {
                            Session["adminName"] = UserName;
                            Response.Redirect("default.aspx");
                            return;
                        }
                        else
                        {
                            Response.Write("<script>alert('用户名或者密码错误');location='login.aspx';</script>");
                            return;
                        }
                    }
                    else
                    {
                        Response.Write("<script>alert('用户名或者密码错误');location='login.aspx';</script>");
                        return;
                    }
                }
            }
            else
            {
                Response.Write("<script>alert('验证码错误');location='login.aspx';</script>");
                return;
            }
        }
    }
}